﻿using Dapper;
using ZilLion.Service.Core.ConfigManager.Attribute;
using ZilLion.Service.Core.ConfigManager.Provider;

namespace ZilLion.Service.Core.DapperWrapper
{
    [ConfigurationArgument(typeof(DapperConfig), typeof(JsonConfigProvider))]
    public class DapperConfig
    {
        private int? _commandTimeout = 0;

        /// <summary>
        ///     Specifies the default Command Timeout for all Queries
        /// </summary>
        public int? CommandTimeout
        {
            get { return _commandTimeout; }
            set
            {
                if (_commandTimeout != value)
                {
                    SqlMapper.Settings.CommandTimeout = value;// Dapper执行 超时时间设为0
                }
                _commandTimeout = value;

            }
        }

        /// <summary>
        ///     Indicates whether nulls in data are silently ignored (default) vs actively applied and assigned to members
        /// </summary>
        public bool ApplyNullValues { get; set; } = false;

        /// <summary>
        /// 默认连接
        /// </summary>
        public string DefaultConnection { get; set; } = string.Empty;
    }
}